/*
 * @Description: Api
 * @Author: seadon
 * @LastEditors: qiyu qiyu@byteluck.com
 * @Date: 2021-07-06 10:16:41
 * @LastEditTime: 2023-03-02 18:08:36
 */
// import { HttpClient } from '@/utils'
import { getFetch } from '@/utils'
import BaseAuto from './baseInfo/services.auto'
import ServiceAuto from './services.auto'
import UserCenterAuto from './userCenter/services.auto'
import ManageAuto from './manage/services.auto'
import DelegateAuto from './delegate/services.auto' // 流程授权接口
import PortalExtend from './portal/extend'
import BaseInfoNew from './baseAuto'

let serviceAuto: ServiceAuto,
	baseAuto: BaseAuto,
	userCenterAuto: UserCenterAuto,
	manageAuto: ManageAuto,
	delegateAuto: DelegateAuto,
	portalExtend: PortalExtend,
	baseInfoNew: BaseInfoNew

export function apiInit() {
	if (serviceAuto === undefined) {
		const httpClient = getFetch(process.env.VUE_APP_API_PATH ?? '')
		// const httpClient = new HttpClient(process.env.VUE_APP_API_PATH)
		serviceAuto = new ServiceAuto(httpClient)
	}

	if (baseAuto === undefined) {
		// const baseHttpClient = new HttpClient(process.env.VUE_APP_API_BASE)
		const baseHttpClient = getFetch(process.env.VUE_APP_API_BASE ?? '')
		baseAuto = new BaseAuto(baseHttpClient)
	}

	if (userCenterAuto === undefined) {
		// const baseHttpClient = new HttpClient(process.env.VUE_APP_API_BASE)
		const userCenterHttpClient = getFetch(
			process.env.VUE_APP_API_USER_CENTER ?? ''
		)
		userCenterAuto = new UserCenterAuto(userCenterHttpClient)
	}
	if (manageAuto === undefined) {
		// const baseHttpClient = new HttpClient(process.env.VUE_APP_API_BASE)
		const manageHttpClient = getFetch(process.env.VUE_APP_API_MANAGE ?? '')
		manageAuto = new ManageAuto(manageHttpClient)
	}
	if (portalExtend === undefined) {
		// const baseHttpClient = new HttpClient(process.env.VUE_APP_API_BASE)
		const portalExtendHttpClient = getFetch(process.env.VUE_APP_API_PATH ?? '')
		portalExtend = new PortalExtend(portalExtendHttpClient)
	}
	if (delegateAuto === undefined) {
		// const baseHttpClient = new HttpClient(process.env.VUE_APP_API_BASE)
		const delegateHttpClient = getFetch(process.env.VUE_APP_BASE_PATH ?? '')
		delegateAuto = new DelegateAuto(delegateHttpClient)
	}
	if (baseInfoNew === undefined) {
		const baseInfoNewApi = getFetch(process.env.VUE_APP_BASE_INFO_PATH ?? '')
		baseInfoNew = new BaseInfoNew(baseInfoNewApi)
	}

	return {
		default: serviceAuto,
		baseAuto: baseAuto,
		userCenterAuto: userCenterAuto,
		manageAuto: manageAuto,
		delegateAuto: delegateAuto,
		portalExtend: portalExtend,
		baseInfoNew: baseInfoNew,
	}
}
